<template>
 <div>

    <el-table
      :data="bannerlist"
      style="width: 100%;"
      border
    >
      <el-table-column prop="id" label="编号">
      </el-table-column>
      <el-table-column prop="title" label="轮播图名称">
      </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="item">
          <div>
            <img class="imgurl" :src="$imgUrl + item.row.img" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            <el-tag v-if="item.row.status==1" type="success">启动</el-tag>
            <el-tag v-else type="danger">禁用</el-tag>
          </div>
        </template>
         </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="del(item.row.id)"
            ></el-button>
            <el-button type="primary" icon="el-icon-edit" @click="edit(item.row.id)"></el-button>
            <el-button icon="el-icon-search"></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
 </div>
</template>

<script>
import {mapGetters,mapActions} from 'vuex'
import { bannerdelete } from "../../util/request/api";
export default {
  data() {
    return {
    };
  },
   computed:{
    ...mapGetters({
      bannerlist:'banner/getbannerList'
    })
  },
mounted() {
    this.getbannerlist()
  },
  methods: {
     ...mapActions({
      getbannerlist:'banner/getbannerAction'
    }),
    edit(id) {
      this.$emit("edit",id);
    },
    del(id) {
      this.$confirm("你确定要删除当前这条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          bannerdelete({ id }).then((res) => {
            if (res.code == 200) {
            this.getbannerlist()
            this.$message.success(res.msg);
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-menu {
  margin: -20px;
  margin-bottom: 20px;
}
img{
  width: 100px;
  height: 60px;
}
</style>